package com.kye.express.business.online_pay.detail;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.kye.express.R;
import com.kye.express.business.base.BaseToolbarActivity;
import com.kye.express.business.invoice_online.detail.ElectronicInvoiceFragment;
import com.kye.express.business.invoice_online.detail.InvoiceDetailFragment;
import com.kye.express.business.invoice_online.detail.InvoiceDetailListener;
import com.kye.express.business.invoice_online.detail.WaybillListFragment;
import com.kye.express.databinding.ActivityBaseFragmentContainsBinding;
import com.kye.model.bean.invoice_online.GetInvoiceDetailResultBean;
import com.kye.model.bean.online.GetPayRecordDetailsResultBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 支付详情
 */
public class OnlinePayDetailActivity extends BaseToolbarActivity implements OnlinePayDetailListener {
    private static final String ARG_DATA = "data";
    private static final String ARG_IS_PAY_RESULT = "is_pay_result";
    private ActivityBaseFragmentContainsBinding mBinding;
    private String mWaybill = "";
    private boolean mIsPayResult = false;//是否是支付成功后跳转的页面

    public static void startActivity(Context context, String waybill, boolean isPayResult) {
        Intent intent = new Intent(context, OnlinePayDetailActivity.class);
        intent.putExtra(ARG_DATA, waybill);
        intent.putExtra(ARG_IS_PAY_RESULT, isPayResult);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_base_fragment_contains);
        setUpToolbar((Toolbar) findViewById(R.id.toolbar));
        mWaybill = getIntent().getStringExtra(ARG_DATA);
        mIsPayResult = getIntent().getBooleanExtra(ARG_IS_PAY_RESULT, false);
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.replace(R.id.contains, OnlinePayDetailFragment.newInstance(mWaybill,mIsPayResult)).commit();
        transaction.addToBackStack(null);
    }

    @Override
    public void onOpenWaybillList(List<GetPayRecordDetailsResultBean.PayDtlBean.ReceivDtlBean> waybillNoDataBeans) {
        if (waybillNoDataBeans != null && waybillNoDataBeans.size() > 0) {
            List<GetInvoiceDetailResultBean.WaybillNoDataBean> waybillList = new ArrayList<>();
            for (GetPayRecordDetailsResultBean.PayDtlBean.ReceivDtlBean item : waybillNoDataBeans) {
                GetInvoiceDetailResultBean.WaybillNoDataBean waybillNoDataBean = new GetInvoiceDetailResultBean.WaybillNoDataBean();
                waybillNoDataBean.setWaybill(item.getWaybill());
                waybillNoDataBean.setInvoicedAmount(item.getPayMoney());
                waybillList.add(waybillNoDataBean);
            }
            FragmentTransaction transaction = getSupportFragmentManager()
                    .beginTransaction();
            transaction.replace(R.id.contains, WaybillListFragment.newInstance(waybillList)).commit();
            transaction.addToBackStack(null);
        }
    }
}
